package sole

import "event-chain/core/common"

type IHandler[T any] interface {
	common.IOnce
	Handle(data T) T
}

type Handler[T any] struct {
	common.One
	handle func(T) T
}

func NewHandler[T any](handle func(T) T, isOnce bool) *Handler[T] {
	res := &Handler[T]{handle: handle}
	res.SetOnce(isOnce)
	return res
}

func (h *Handler[T]) Handle(data T) T {
	return h.handle(data)
}
